{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Preparation \n",
    "## Append to path and import\n",
    "In case gumpy is not installed as package, you may have to specify the path to the gumpy directory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt \n",
    "\n",
    "import sys, os, os.path\n",
    "sys.path.append('../..')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## import gumpy\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This may take a while, as gumpy as several dependencies that will be loaded automatically"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import gumpy\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import data\n",
    "To import data, you have to specify the directory in which your data is stored in. For the example given here, the data is in the subfolder ``../EEG-Data/Graz_data/data``. \n",
    "Then, one of the classes that subclass from ``dataset`` can be used to load the data. In the example, we will use the GrazB dataset, for which ``gumpy`` already includes a corresponding class. If you have different data, simply subclass from ``gumpy.dataset.Dataset``."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<gumpy.data.nst_emg.NST_EMG at 0x7f1956bc3390>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# First specify the location of the data and some \n",
    "# identifier that is exposed by the dataset (e.g. subject)\n",
    "base_dir = '../..'\n",
    "subject = 'S1'\n",
    "\n",
    "# The next line first initializes the data structure. \n",
    "# Note that this does not yet load the data! In custom implementations\n",
    "# of a dataset, this should be used to prepare file transfers, \n",
    "# for instance check if all files are available, etc.\n",
    "data_low = gumpy.data.NST_EMG(base_dir, subject, 'low')\n",
    "data_high = gumpy.data.NST_EMG(base_dir, subject, 'high') \n",
    "\n",
    "# Finally, load the dataset\n",
    "data_low.load()\n",
    "data_high.load()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The abstract class allows to print some information about the contained data. This is a commodity function that allows quick inspection of the data as long as all necessary fields are provided in the subclassed variant."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data identification: NST_EMG-S1\n",
      "EMG-data shape: (217613, 8)\n",
      "Trials data shape:  (36,)\n",
      "Labels shape:  (48,)\n",
      "Total length of single trial:  10\n",
      "Sampling frequency of EMG data: 512\n",
      "Interval for motor imagery in trial:  [5, 10]\n",
      "Classes possible:  [0. 1. 2. 3.]\n",
      "----------\n",
      "Data identification: NST_EMG-S1\n",
      "EMG-data shape: (217618, 8)\n",
      "Trials data shape:  (36,)\n",
      "Labels shape:  (48,)\n",
      "Total length of single trial:  10\n",
      "Sampling frequency of EMG data: 512\n",
      "Interval for motor imagery in trial:  [5, 10]\n",
      "Classes possible:  [0. 1. 2. 3.]\n"
     ]
    }
   ],
   "source": [
    "data_low.print_stats()\n",
    "print('----------')\n",
    "data_high.print_stats()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Signal Filtering"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#bandpass\n",
    "lowcut=20\n",
    "highcut=255\n",
    "#notch\n",
    "f0=50\n",
    "Q=50\n",
    "\n",
    "flt_low = gumpy.signal.butter_bandpass(data_low, lowcut, highcut)\n",
    "flt_low = gumpy.signal.notch(flt_low, cutoff=f0, Q=Q)\n",
    "\n",
    "trialsLow = gumpy.utils.getTrials(data_low, flt_low)\n",
    "trialsLowBg = gumpy.utils.getTrials(data_low, flt_low, True)\n",
    "\n",
    "flt_high = gumpy.signal.butter_bandpass(data_high, lowcut, highcut)\n",
    "flt_high = gumpy.signal.notch(flt_high, cutoff=f0, Q=Q)\n",
    "\n",
    "trialsHigh = gumpy.utils.getTrials(data_high, flt_high)\n",
    "trialsHighBg = gumpy.utils.getTrials(data_high, flt_high, True)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  Data Visualization "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAD8CAYAAACVZ8iyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvFvnyVgAAIABJREFUeJzt3Xd8FGX+B/DPNwkhdELvhI4gPdJFelc4K1hQT8U70Tv11MOOYkFOPQ8LHth/iuLZQAHpRaUZeofQCSV0kBaSPL8/dnYzuzuzvc/n/XrxYnd2ZvaZze7znaeLUgpERGRtSdFOABERRR+DARERMRgQERGDARERgcGAiIjAYEBERGAwICIiMBgQEREYDIiICEBKtBPgq0qVKqmMjIxoJ4OIKG6sWrXqmFKqsi/7xk0wyMjIQFZWVrSTQUQUN0Rkr6/7spqIiIgYDIiIiMGAiIjAYEBERGAwICIiMBgQEREYDIiICAwGlnLqfB5mrD8U7WQQUQxiMLCQUVNWY9SU1cg5dSHaSSGiGMNgYCE5J21BIC+/MMopIaJYw2BAREQMBkRExGBgSUqpaCeBiGIMg4GFiEi0k0BEMYrBwEJYIiAiMwwGFsQSAhG5YjCwIJYQiMgVg4GFsERARGYYDIiIiMGAiIhCFAxE5CMRyRWRjbptY0QkR0TWav8G6l57UkSyRWSbiPQLRRrIO7YVEJGZUJUMPgHQ32D7v5VSrbV/MwFARJoBGAaguXbMeyKSHKJ0UIzJLyjEJ7/txuUCzodEFMtCEgyUUksAnPBx9yEAvlJKXVJK7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fwHCXq9Sqkc7f9c2AJ9e8Tw9ziRg8HvABppPRVSYWuAmh7lNIXSdAD2ngV3omj21+kARmi9EzoCOK0VS2cD6Csi6VoPhr7atpii1Ql/CGCLUupN3UsJd71im923vPa4BIA+sLWRLARwo7ab67XaP4MbASxQtlbG6QCGab1v6sE2S/DKyFyF75RSTyqlaimlMmD7PS5QSt2GBLxeESklImXsj2H7/m1ELH+Po93iHs5/sLXQb4etHvbpaKcniOv4ErYFgy7DVmd4D2x1p/MB7AAwD0AFbV8B8K52zRsAZOrO82fYGtuyAdwd7esyudausNW1rgewVvs3MBGvF0BLAGu0a90I4Dlte33YMrdsAP8DUFzbnqY9z9Zer68719PaZ7ANwIBoX5sP194dRb2JEu56tWtap/3bZM9/Yvl7zBHIRESU0NVERETkIwYDIiJiMCAiIgYDIiICgwEREYHBgIiIwGBARERgMCAiIgD/DxWDVobfWHrAAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "512"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i=15\n",
    "plt.figure()\n",
    "plt.plot(flt_low[data_low.trials[i]: data_low.trials[i+1],4])\n",
    "#plt.plot(data_low.raw_data[data_low.trials[i]: data_low.trials[i+1],2])\n",
    "plt.show()\n",
    "data_high.sampling_freq"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Features Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.00317433, 0.00347712, 0.00351526, ..., 0.0009686 , 0.00128107,\n",
       "        0.00107977],\n",
       "       [0.00362845, 0.00595219, 0.00753056, ..., 0.00087038, 0.00078948,\n",
       "        0.00062584],\n",
       "       [0.00309323, 0.00401737, 0.00336045, ..., 0.0010687 , 0.00079988,\n",
       "        0.00072598],\n",
       "       ...,\n",
       "       [0.00212149, 0.00193713, 0.0020841 , ..., 0.00049861, 0.0005653 ,\n",
       "        0.00119055],\n",
       "       [0.00195615, 0.00182604, 0.00189547, ..., 0.00057526, 0.00064521,\n",
       "        0.00068972],\n",
       "       [0.00162141, 0.00206098, 0.00338333, ..., 0.00065747, 0.00061476,\n",
       "        0.00061072]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "window_size = 0.2\n",
    "window_shift = 0.05\n",
    "\n",
    "highRMSfeatures = gumpy.features.RMS_features_extraction(data_high, trialsHigh, window_size, window_shift)\n",
    "highRMSfeaturesBg = gumpy.features.RMS_features_extraction(data_high, trialsHighBg, window_size, window_shift)\n",
    "lowRMSfeatures = gumpy.features.RMS_features_extraction(data_high, trialsLow, window_size, window_shift)\n",
    "lowRMSfeaturesBg = gumpy.features.RMS_features_extraction(data_high, trialsLowBg, window_size, window_shift)\n",
    "\n",
    "\n",
    "\n",
    "# Constructing Classification arrays\n",
    "X_tot = np.vstack((highRMSfeatures, lowRMSfeatures))\n",
    "y_tot = np.hstack((np.ones((highRMSfeatures.shape[0])),\n",
    "                     np.zeros((lowRMSfeatures.shape[0]))))\n",
    "  \n",
    "X_totSig = np.vstack((highRMSfeatures, highRMSfeaturesBg, lowRMSfeatures, lowRMSfeaturesBg))\n",
    "# Normalizing the features\n",
    "X_totSig = X_totSig/np.linalg.norm(X_totSig)\n",
    "\n",
    "y_totSig = np.hstack((data_high.labels, \n",
    "                     data_low.labels))\n",
    "\n",
    "X_totSig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2., 1., 2., 2., 1., 0., 1., 2., 0., 1., 0., 0., 2., 1., 2., 1., 0.,\n",
       "       1., 1., 0., 0., 2., 0., 2., 1., 2., 0., 1., 2., 0., 0., 1., 1., 0.,\n",
       "       2., 2., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 0., 1., 1.,\n",
       "       0., 2., 2., 2., 2., 0., 0., 1., 1., 2., 1., 2., 0., 0., 0., 0., 2.,\n",
       "       1., 2., 1., 1., 1., 1., 2., 2., 1., 1., 0., 0., 2., 2., 0., 0., 3.,\n",
       "       3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels=y_totSig\n",
    "labels"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Normalization of features "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Normalized Data:\n",
      "  Mean    = 0.000\n",
      "  Min     = -2.636\n",
      "  Max     = 5.390\n",
      "  Std.Dev = 1.000\n"
     ]
    }
   ],
   "source": [
    "features =X_totSig\n",
    "labels =y_totSig\n",
    "\n",
    "# normalize the data first\n",
    "features = gumpy.signal.normalize(features, 'mean_std')\n",
    "# let's see some statistics\n",
    "print(\"\"\"Normalized Data:\n",
    "  Mean    = {:.3f}\n",
    "  Min     = {:.3f}\n",
    "  Max     = {:.3f}\n",
    "  Std.Dev = {:.3f}\"\"\".format(\n",
    "  np.nanmean(features),np.nanmin(features),np.nanmax(features),np.nanstd(features)\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Splitting data for training \n",
    "Now that we extracted features (and reduced the dimensionality), we can split the data for test and training purposes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.00241969, 0.0022337 , 0.0023087 , ..., 0.00084206, 0.00076152,\n",
       "        0.00103709],\n",
       "       [0.00316464, 0.00331519, 0.00239209, ..., 0.00194006, 0.0019764 ,\n",
       "        0.00227144],\n",
       "       [0.00433969, 0.00631524, 0.00652404, ..., 0.00064123, 0.00075638,\n",
       "        0.00059114],\n",
       "       ...,\n",
       "       [0.00233438, 0.0031688 , 0.00322296, ..., 0.00297931, 0.00107865,\n",
       "        0.00169824],\n",
       "       [0.00252272, 0.00243595, 0.00187793, ..., 0.00090753, 0.00114431,\n",
       "        0.00146587],\n",
       "       [0.00252272, 0.00243595, 0.00187793, ..., 0.00090753, 0.00114431,\n",
       "        0.00146587]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# gumpy exposes several methods to split a dataset, as shown in the examples:\n",
    "if 1: \n",
    "    split_features = np.array(gumpy.split.normal(features, labels,test_size=0.2))\n",
    "if 0: \n",
    "    n_splits=5\n",
    "    split_features = np.array(gumpy.split.time_series_split(features, labels, n_splits)) \n",
    "if 0: \n",
    "    split_features = np.array(gumpy.split.normal(PCA, labels, test_size=0.2))\n",
    "    \n",
    "#ShuffleSplit: Random permutation cross-validator \n",
    "if 0: \n",
    "    split_features = gumpy.split.shuffle_Split(features, labels, n_splits=10,test_size=0.2,random_state=0)\n",
    "    \n",
    "# #Stratified K-Folds cross-validator\n",
    "# #Stratification is the process of rearranging the data as to ensure each fold is a good representative of the whole   \n",
    "if 0: \n",
    "    split_features = gumpy.split.stratified_KFold(features, labels, n_splits=3)\n",
    "    \n",
    "#Stratified ShuffleSplit cross-validator    \n",
    "if 0: \n",
    "    split_features = gumpy.split.stratified_shuffle_Split(features, labels, n_splits=10,test_size=0.3,random_state=0)\n",
    "\n",
    "\n",
    "# the functions return a list with the data according to the following example\n",
    "X_train = split_features[0]\n",
    "X_test = split_features[1]\n",
    "Y_train = split_features[2]\n",
    "Y_test = split_features[3]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#SVM, RF, KNN, NB, LR, QLDA, LDA\n",
    "from sklearn.cross_validation import cross_val_score\n",
    "feature_idx, cv_scores, algorithm,sfs, clf = gumpy.features.sequential_feature_selector(X_train, Y_train, 'SVM',(6, 30), 3, 'SFFS')\n",
    "\n",
    "feature=X_train[:,feature_idx]\n",
    "# features=features[:,feature_idx]\n",
    "scores = cross_val_score(clf, feature, Y_train, cv=3)\n",
    "# scores = cross_val_score(clf, features, labels, cv=5)\n",
    "\n",
    "\n",
    "print(\"Validation Accuracy: %0.2f (+/- %0.2f)\" % (scores.mean(), scores.std() * 2))\n",
    "clf.fit(feature, Y_train)\n",
    "feature1=X_test[:,feature_idx]\n",
    "feature1.shape\n",
    "clf.predict(feature1)\n",
    "f=clf.score(feature1, Y_test)\n",
    "print(\"Test Accuracy:\",f )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Gesture Classification"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    # Posture Classification\n",
    "    classifiers = []\n",
    "    Accuracy=[]\n",
    "    Final_results = {}\n",
    "    for model in gumpy.classification.available_classifiers:\n",
    "        print (model)\n",
    "        feature_idx, cv_scores, algorithm, sfs, clf = gumpy.features.sequential_feature_selector(features, labels,model,(6, 25), 3, 'SFFS')\n",
    "        classifiers.append(model)\n",
    "        Accuracy.append (cv_scores*100) \n",
    "        Final_results[model]= cv_scores*100\n",
    "        print (Final_results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Force classification"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if __name__ == '__main__':\n",
    "    # Posture Classification\n",
    "    classifiers = []\n",
    "    Accuracy=[]\n",
    "    Final_results = {}\n",
    "    for model in gumpy.classification.available_classifiers:\n",
    "        print (model)\n",
    "        feature_idx, cv_scores, algorithm = gumpy.features.sequential_feature_selector(X_tot, y_tot, model,(6, 25), 10, 'SFFS')\n",
    "        classifiers.append(model)\n",
    "        Accuracy.append (cv_scores*100) \n",
    "        Final_results[model]= cv_scores*100\n",
    "print (Final_results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Classification without the feature selection method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "classifiers = []\n",
    "Accuracy=[]\n",
    "Final_results = {}\n",
    "for model in gumpy.classification.available_classifiers:\n",
    "    results, clf = gumpy.classify(model, X_train, Y_train, X_test, Y_test)\n",
    "    print (model)\n",
    "    classifiers.append(model)\n",
    "    Accuracy.append (results.accuracy) \n",
    "    Final_results[model]= results.accuracy\n",
    "print (Final_results)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
